package file;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import data.Data;

public class Parsing3Classes {
	List<Data> list = new ArrayList<Data>();
	List<Data> pos = new ArrayList<Data>();
	List<Data> neu = new ArrayList<Data>();
	List<Data> neg = new ArrayList<Data>();
	
	double pavg;
	double navg;
	
	public Parsing3Classes(String data, String sign) throws IOException {
		BufferedReader dataReader = new BufferedReader(new FileReader(data));
		BufferedReader signReader = new BufferedReader(new FileReader(sign));
		String line;
		double psum = 0.0;
		int pnum = 0;
		
		double nsum = 0.0;
		int nnum = 0;
		
		int znum = 0;
		
		while((line = dataReader.readLine()) != null){
			String[] field = line.split(",");
			int uid = Integer.parseInt(field[0]);
			short iid = Short.parseShort(field[1]);
			byte rat = Byte.parseByte(field[2]);
			
			Data datum = new Data(uid, iid, rat);
			list.add(datum);
			
			String line2 = signReader.readLine();
			int cls = Integer.parseInt(line2);
			if (cls > 0) {
				pos.add(datum);
				psum += rat;
				pnum++;
			}
			else if (cls < 0) {
				neg.add(datum);
				nsum += rat;
				nnum++;
			}
			else {
				neu.add(datum);
				znum++;
			}
		}
		dataReader.close();
		signReader.close();
		
		System.out.println("Num of pos "+pnum);
		System.out.println("Num of neg "+nnum);
		System.out.println("Num of neu "+znum);
		
		pavg = psum / pnum;
		navg = nsum /nnum;
		
		System.out.println("Pos avg "+pavg);
		System.out.println("Neg avg "+navg);
		
	}

	public List<Data> getPos() {
		return pos;
	}

	public List<Data> getNeu() {
		return neu;
	}

	public List<Data> getNeg() {
		return neg;
	}

	public double getPavg() {
		return pavg;
	}

	public double getNavg() {
		return navg;
	}

	public List<Data> getList() {
		return list;
	}
}
